<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" type="image/png" sizes="16x16" href="./assets/images/favicon.png">
    <title>图书管理系统</title>
    <link rel="stylesheet" type="text/css" href="./assets/extra-libs/multicheck/multicheck.css">
    <link href="./assets/libs/datatables.net-bs4/css/dataTables.bootstrap4.css" rel="stylesheet">
    <link href="./dist/css/style.min.css" rel="stylesheet">
    <script src="./assets/libs/jquery/dist/jquery.min.js"></script>
    <script src="./assets/libs/popper.js/dist/umd/popper.min.js"></script>
    <script src="./assets/libs/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="./assets/libs/perfect-scrollbar/dist/perfect-scrollbar.jquery.min.js"></script>
    <script src="./assets/extra-libs/sparkline/sparkline.js"></script>
    <script src="./dist/js/waves.js"></script>
    <script src="./dist/js/sidebarmenu.js"></script>
    <script src="./dist/js/custom.min.js"></script>
    <script src="./assets/extra-libs/multicheck/datatable-checkbox-init.js"></script>
    <script src="./assets/extra-libs/multicheck/jquery.multicheck.js"></script>
    <script src="./assets/extra-libs/DataTables/datatables.min.js"></script>
<!--    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>-->
<!--    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>-->
</head>

<body>

<div class="preloader">
    <div class="lds-ripple">
        <div class="lds-pos"></div>
        <div class="lds-pos"></div>
    </div>
</div>

<div id="main-wrapper">

    <header class="topbar" data-navbarbg="skin5">
        <nav class="navbar top-navbar navbar-expand-md navbar-dark">
            <div class="navbar-header" data-logobg="skin5">
                <a class="nav-toggler waves-effect waves-light d-block d-md-none" href="javascript:void(0)"><i class="ti-menu ti-close"></i></a>
                <a class="navbar-brand" href="index.html">
                    <!-- Logo icon -->
                    <b class="logo-icon p-l-10">
                        <img src="./assets/images/logo-icon.png" alt="homepage" class="light-logo" />
                    </b>
                    <span class="logo-text">
                             <img src="./assets/images/logo-text.png" alt="homepage" class="light-logo" />
                        </span>
                </a>
                <a class="topbartoggler d-block d-md-none waves-effect waves-light" href="javascript:void(0)" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"><i class="ti-more"></i></a>
            </div>

            <div class="navbar-collapse collapse" id="navbarSupportedContent" data-navbarbg="skin5">

                <ul class="navbar-nav float-left mr-auto">
                    <li class="nav-item d-none d-md-block"><a class="nav-link sidebartoggler waves-effect waves-light" href="javascript:void(0)" data-sidebartype="mini-sidebar"><i class="mdi mdi-menu font-24"></i></a></li>

                </ul>

                <ul class="navbar-nav float-right">

                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle text-muted waves-effect waves-dark pro-pic" href="" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><img src="./assets/images/users/1.jpg" alt="user" class="rounded-circle" width="31"></a>
                        <div class="dropdown-menu dropdown-menu-right user-dd animated">
                            <a class="dropdown-item" href="modifypassword.html"><i class="ti-user m-r-5 m-l-5"></i> 修改密码</a>
                            <div class="dropdown-divider"></div>
<!--                            <a class="dropdown-item" href="index.html"><i class="fa fa-power-off m-r-5 m-l-5"></i> 注销</a>-->
<!--                            <a class="dropdown-item" href="index.html" onclick="logout()"><i class="fa fa-power-off m-r-5 m-l-5"></i> 注销</a>-->
<!--                            <a class="dropdown-item" href="index.html" onclick="logout(event)"><i class="fa fa-power-off m-r-5 m-l-5"></i> 注销</a>-->
<!--                            <a class="dropdown-item" href="/users/logout"> <i class="fa fa-power-off m-r-5 m-l-5"></i> 注销</a>-->
                            <a class="dropdown-item" href="index.html" onclick="logout()"> <i class="fa fa-power-off m-r-5 m-l-5"></i> 注销</a>

                        </div>
                    </li>

                </ul>
            </div>
        </nav>
    </header>

    <aside class="left-sidebar" data-sidebarbg="skin5">
        <!-- Sidebar scroll-->
        <div class="scroll-sidebar">
            <!-- Sidebar navigation-->
            <nav class="sidebar-nav">
                <ul id="sidebarnav" class="p-t-30">
                    <li class="sidebar-item"> <a class="sidebar-link waves-effect waves-dark sidebar-link" href="mainpage.html" aria-expanded="false"><i class="mdi mdi-view-dashboard"></i><span class="hide-menu">读者系统主页</span></a></li>
                    <li class="sidebar-item"> <a class="sidebar-link waves-effect waves-dark sidebar-link" href="myinfo.html" aria-expanded="false"><i class="mdi mdi-view-dashboard"></i><span class="hide-menu">个人信息</span></a></li>
                    <li class="sidebar-item"> <a class="sidebar-link waves-effect waves-dark sidebar-link" href="querybook.html" aria-expanded="false"><i class="mdi mdi-view-dashboard"></i><span class="hide-menu">查询图书信息</span></a></li>
                    <li class="sidebar-item"> <a class="sidebar-link waves-effect waves-dark sidebar-link" href="myborrow.html" aria-expanded="false"><i class="mdi mdi-view-dashboard"></i><span class="hide-menu">我的借阅信息</span></a></li>
                    <li class="sidebar-item"> <a class="sidebar-link waves-effect waves-dark sidebar-link" href="borrowhistory.html" aria-expanded="false"><i class="mdi mdi-view-dashboard"></i><span class="hide-menu">我的借阅历史</span></a></li>
                    <li class="sidebar-item"> <a class="sidebar-link waves-effect waves-dark sidebar-link" href="myreservation.html" aria-expanded="false"><i class="mdi mdi-view-dashboard"></i><span class="hide-menu">我的预定</span></a></li>
                </ul>
            </nav>
        </div>
    </aside>

    <div class="page-wrapper">

        <div class="page-breadcrumb">
            <div class="row">
                <div class="col-12 d-flex no-block align-items-center">
                    <h4 class="page-title">我的主页</h4>
                </div>
            </div>
        </div>

        <div class="container-fluid">

            <div class="row">
                <div class="col-12">

                    <div class="card">
                        <div class="card-body">
                            <h5 class="card-title m-b-0">通知：</h5>
                            <div class="border-top">
                                <table id="notification" width="90%">
                                    <thead>
                                    <th>内容</th>
                                    <th>发布时间</th>
                                    </thead>
                                    <tbody id="ntflist">

                                    </tbody>
                                </table>
                            </div>
                        </div>

                    </div>

                    <div class="card" id="shReturntable">
                        <div class="card-body">
                            <h5 class="card-title">以下图书即将到期或已过期，请及时到图书馆还书!</h5>
                            <div class="table-responsive" >
                                <table id="borrowlist" class="table table-striped table-bordered">
                                    <thead>
                                    <tr>
                                        <th style="text-align: center">书名</th>
                                        <th style="text-align: center">作者</th>
                                        <th style="text-align: center">ISBN</th>
                                        <th style="text-align: center">借书时间</th>
                                        <th style="text-align: center">归还期限</th>
                                    </tr>
                                    </thead>
                                    <tbody id="bldata">

                                    </tbody>

                                </table>
                            </div>

                        </div>
                    </div>
                </div>
            </div>

        </div>
        <footer class="footer text-center"><br/><br/>Written by weh <a target="_blank"></a>
        </footer>


    </div>
</div>

<script type="text/javascript">
    $("#shReturntable").hide();
    var id = getCookie("id");
    $.ajax({
        type:"GET",
        url:"/borrow/borrowinfo/notice/" + id,
        dateType:"json",
        success:function (result) {
            if(result.length!=0)
            {
                $("#shReturntable").show();
            }
            createshreturnlist(result)
        }
    })

    $.ajax({
        type:"GET",
        url:"/notification",
        dataType:"json",
        success:function (result) {
            createnotifylist(result)
        }
    })

    function createnotifylist(data) {
        var str="";
        for(var i=0;i<10;i++){
            var j=data.length-1-i;
            str+="<tr style='height: 50px'><td width='85%'>"+data[j].content+"</td><td width='15%'>"+data[j].date+"</td></tr>";
            if (j==0){break;}
        }
        $("#ntflist").html(str);
    }

    function createshreturnlist(data) {
        var str="";
        for(var i=0;i<data.length;i++){
            str += "<tr><td><center>"+data[i].bookName+"</center></td><td><center>"+data[i].author+
                "</center></td><td><center>"+data[i].isbn+"</center></td><td><center>"+data[i].borrowDate+
                "</center></td><td><center>"+data[i].shReturnDate +"</center></td></tr>";
        }
        $("#bldata").html(str);
    }

    function getCookie(cname){
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for(var i=0; i<ca.length; i++) {
            var c = ca[i].trim();
            if (c.indexOf(name)==0) { return c.substring(name.length,c.length); }
        }
        return "";
    }

    function logout() {
        $.ajax({
            type: "POST",
            url: "users/logout",
            dataType: "json",
            success: function(result) {
                window.location.href = "/index.html"; // 页面跳转到index.html
            },
            error: function(xhr, status, error) {
                console.log("注销请求失败: " + error);
            }
        });
    }

</script>
</body>
</html>